package com.mingyuan.library.domain.lending.patron.event;

import com.mingyuan.library.domain.lending.book.model.valueobject.BookId;
import com.mingyuan.library.domain.lending.librarybranch.model.valueobject.LibraryBranchId;
import com.mingyuan.library.domain.lending.patron.model.valueobject.PatronInformation;
import com.mingyuan.library.domain.lending.patron.model.valueobject.Rejection;
import lombok.NonNull;
import lombok.Value;

import java.time.Instant;
import java.util.UUID;

@Value
public class BookHoldFailed implements PatronEvent {
    @NonNull
    UUID eventId = UUID.randomUUID();
    @NonNull
    String reason;
    @NonNull
    Instant when;
    @NonNull
    UUID patronId;
    @NonNull
    UUID bookId;
    @NonNull
    UUID libraryBranchId;

   public static BookHoldFailed bookHoldFailedNow(Rejection rejection, BookId bookId, LibraryBranchId libraryBranchId, PatronInformation patronInformation) {
        return new BookHoldFailed(
                rejection.getReason(),
                Instant.now(),
                patronInformation.getPatronId().getPatronId(),
                bookId.getBookId(),
                libraryBranchId.getLibraryBranchId());
    }
}